home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-06-10 | 26.4 KB | 626 lines | [TEXT/PJMM] |
- unit HelpPackage;
-
- {****************************************************** *}
- {* This is a package of routines to be used for setting your own menu items in the *}
- {* Help menu under System 7 or building a new menu with the title stored in the *}
- {* Global constant HELPMENUTITLE. The menu is appended to the end of the menu bar *}
- {* active during the call to Init Help. The source code was written by Tim Damon in *}
- {* THINK Pascal. It is encouraged to be used in any developement projects, but *}
- {* PLEASE at least give me credit for the long hours of frustrating work. If you *}
- {* wish to use this in a commercial product, please contact me via America Online *}
- {* or mail (Addresses are listed in the documention file.) so I can keep track of who *}
- {* is using it and for which products. Feel free to distribute the source code to *}
- {* anyone and everyone. All I ask is that if you decide to modify the code, please *}
- {* let me know so I can borrow your ideas! : ) If you find a better way of doing *}
- {* things I would appreciate hearing about it. Any other questions or comments? *}
- {* Contact me. All rights reserved. ©1992 Mountainside Software. Tim Damon *}
- {****************************************************** *}
-
- interface
-
- uses
- HelpGlobals, Traps, Types, GestaltEqu, Balloons;
- {*HelpGlobals is the unit containing all global variabls for this package.*}
- {*They must be global to your application as well for the sake of keeping data integrity.*}
-
- const
- TextBox = 2; {*The item number of the text box user item in the Help dialog*}
- {*Must be global to this unit for update events*}
- var
- TEXTHandle: TEHandle; {*The text edit handle for the text*}
- {*Must be global to this unit for update events*}
- TheScrollBar: ControlHandle; {*The handle to the scroll bar*}
- {*Must be global to this unit for tracking the scrollbar in the Help dialog*}
-
- function InitHelp (HmiLID: integer): Integer;
- {*Make a call to this function, providing the resource ID of your main 'HmiL', when setting up your menus.*}
- {*This function sets up the Help menu using the 'HmiL' resources you provide. * }
- {*It will return an error code if it has a problem setting up the menu.*}
-
- function DoHelp (MenuID, TheItem: integer): Integer;
- {*Make a call to this function when your event loop detects a menu choice. Give it the menu ID*}
- {*and the Item number returned from MenuSelect. The function will return with NoMenu*}
- {*if the menu was not associated with the Help menu from System 7 or the Help menu built*}
- {*under an earlier system. If the routine returns with a value other than zero, chances are*}
- {*the help dialog never showed up.*}
-
- procedure DisposeHelp;
- {*Make a call to this routine to dispose of the current Help menu items and data structeres*}
- {*This can be called at anytime during execution.*}
-
- implementation
- {------------------------------------------------------------------------------}
- {-The following routines were taken from Inside Macintosh Volume VI, Chapter 3, pg 8-}
- {------------------------------------------------------------------------------}
- function NumToolboxTraps: Integer;
- begin
- if NGetTrapAddress(_InitGraf, ToolTrap) = NGetTrapAddress($AA6E, ToolTrap) then
- NumToolboxTraps := $200
- else
- NumToolboxTraps := $400;
- end;
-
- function GetTrapType (theTrap: Integer): TrapType;
- const
- TrapMask = $0800;
- begin
- if BAND(theTrap, TrapMask) > 0 then
- GetTrapType := ToolTrap
- else
- GetTrapType := OSTrap;
- end;
-
- function TrapAvailable (theTrap: Integer): Boolean;
- var
- tType: TrapType;
- begin
- tType := GetTrapType(theTrap);
- if tType = ToolTrap then
- begin
- theTrap := BAND(theTrap, $07FF);
- if theTrap >= NumToolboxTraps then
- theTrap := _Unimplemented;
- end;
- TrapAvailable := NGetTrapAddress(theTrap, tType) <> NGetTrapAddress(_Unimplemented, ToolTrap);
- end;
- {-----------------------------------------------------------------------}
-
-
- function BuildMenu (HmiLID: Integer; TheMenuHandle: MenuHandle; whichMenu: Integer; var Err: Integer): MHandle;
- {*InitHelp calls this function, providing the resource ID of your main 'HmiL', to actually build the Help Menu.*}
- {*This function sets up the Help menu using the 'HmiL' resources you provide. * }
- {*It will return an error code if it has a problem setting up the menu. InitHelp will return this error code to you.*}
- type
- ItemListForm = record {*This record contains an item from them 'HmiL' resource.*}
- HierMenu: Boolean;
- HierMenuID: Integer;
- HierMItemListID: Integer;
- HelpTextID: Integer;
- end;
- IListPtr = ^ItemListForm; {*This is a pointer to the ItemListForm record.*}
- intPtr = ^integer; {*Needed to extract an integer off the top of the 'HmiL' resource.*}
-
- var
- TempMHandle: MHandle;
- {*A temporary handle used to make sure the handle was allocated properly.*}
- {*Also for working with fields of the record.*}
- TempMasterHandle: MHandle; {*Used to build the master handle of the menu list.*}
- TheMasterHandle: MHandle; {*This points to the first item of the master item list.*}
- RHandle: Handle; {*A handle to the 'HmiL' resource.*}
- Count: Integer; {*This contains the number of items in the 'HmiL' resource.*}
- Address: Longint; {*This will be used in indexing into the 'HmiL' resource.*}
- TempItemRec: IListPtr; {*A pointer to an item record.*}
- TheItemTitle: Str255; {*Hold the items title when working with the 'HmiL' resource.*}
- HierMHandle: MenuHandle; {*A handle to a new hierarchical menu.*}
- TempPtr: StringPtr; {*A temporary pointer to the title.*}
- TempP: IntPtr; {*A temporary pointer for getting the address of the resource in memory.*}
-
- begin
- Err := noErr; {*Initially return an error code of zero*}
- BuildMenu := nil; {*Initially return a nil handle in case of error.*}
- TempMasterHandle := MHandle(NewHandle(SizeOf(MItemList))); {*Create a temporary handle to hold this item.*}
- if TempMasterHandle = nil then {*Check to make sure the handle was allocated properly.*}
- begin
- Err := NilHandle; {*If not, return from function with proper error code.*}
- Exit(BuildMenu);
- end;
- TheMasterHandle := TempMasterHandle; {*Hold the handle to the first item in the item list.*}
- RHandle := GetResource('HmiL', HmiLID); {*Read in the 'HmiL' resource.*}
- if RHandle = nil then {*Check to see if the resource was read into memory.*}
- begin
- Err := HmiLNotAvail; {*If not, return from function with proper error code.*}
- Exit(BuildMenu);
- end;
-
- HLock(RHandle); {*Lock the handle down since we will be dereferencing it into an address shortly.*}
- TempP := intPtr(stripAddress(RHandle^)); {*Create a pointer to the first integer in the 'HmiL' resource*}
- Count := TempP^; {*Take the first integer in the resource and save for use in looping.*}
- Address := Ord4(stripAddress(RHandle^)); {*Get the stripped address of the resource in memory.*}
- repeat
- Address := Address + 2; {*Move the address up two bytes to miss the integer we are pointing at now.*}
- TempPtr := StringPtr(Pointer(Address)); {*Get a temporary pointer to the current address.*}
- TheItemTitle := TempPtr^; {*Get the item's title directly from the address location.*}
- Address := Address + Length(TheItemTitle) + 1; {*Calculate the new address*}
-
- if (length(TheItemTitle) mod 2 = 0) then
- Address := Address + 1;
- {*If the Title length is odd, account for the padding.*}
-
- TempItemRec := IListPtr(Pointer(Address));
- {*Force the rest of the first item into a record for easier usage.*}
- if TempItemRec^.HierMenu then {*If this item is a hierarchical menu then build that menu*}
- begin
- TheItemTitle := Concat(TheItemTitle, '/', chr($1B), '!', chr(TempItemRec^.HierMenuID));
- {*Set up the item title for use as a hierarchical menu.*}
- AppendMenu(TheMenuHandle, TheItemTitle); {*Stick it in the menu.*}
- HierMHandle := NewMenu(TempItemRec^.HierMenuID, 'Hier Help Menu');
- {*Create a new menu for the hierarchical item.*}
- TheMenu[whichMenu].ID := TempItemRec^.HierMenuID; {*Add this menu ID to the array of menus.*}
- InsertMenu(HierMHandle, -1); {*Insert the new menu.*}
- whichMenu := whichMenu + 1; {*We are on the next menu now.*}
- TheMenu[whichMenu].Master := BuildMenu(TempItemRec^.HierMItemListID, HierMHandle, whichMenu, Err);
- {*Recursively call this function to build each menu as we come to it.*}
- if Err <> noErr then
- Exit(BuildMenu); {*If we had an error, drop out of the BuildMenu routine with the appropriate error code.*}
- whichMenu := whichMenu - 1; {*We are on the previous menu again.*}
- end
- else
- begin
- AppendMenu(TheMenuHandle, TheItemTitle); {*If not hierarchical menu, add this item to the menu.*}
- TheMenu[whichMenu].ID := TheMenuHandle^^.menuID; {*Set the menu ID in the array*}
- end;
- TempMasterHandle^^.ItemTitle := TheItemTitle; {*Store the item's title in our menu list.*}
- TempMasterHandle^^.HelpTextID := TempItemRec^.HelpTextID; {*Store the ID of the help text resource in our menu list.*}
-
- if (Count - 1) = 0 then {*Check to see if we are on last item.*}
- TempMasterHandle^^.NextItem := nil {*If so, there is no next item so make it nil.*}
- else
-
- begin {*If we are not on the last item, allocate space for the next item.*}
- TempMHandle := MHandle(NewHandle(SizeOf(MItemList))); {*Get a handle to our next item.*}
- if TempMHandle = nil then {*Check to make sure the handle was allocated properly.*}
- begin
- Err := NilHandle; {*If not, return from function with proper error code.*}
- Exit(BuildMenu);
- end;
- TempMasterHandle^^.NextItem := TempMHandle; {*Store the handle to our next item in our menu list.*}
- TempMasterHandle := TempMHandle; {*Set the master handle to the next Item.*}
- end;
-
- Address := Ord4(@TempItemRec^.HelpTextID); {*Move our address up to the last item in this record.*}
- Count := Count - 1; {*We processed one item so remove from the count of items.*}
-
- until Count = 0; {*We are done when count reaches zero*}
- HUnlock(RHandle); {*Unlock the handle we were just working with*}
- ReleaseResource(RHandle); {*Release the resource since we don't need it anymore*}
- BuildMenu := TheMasterHandle; {*Return the master handle to the calling routine.*}
- end;
- {-----------------------------------------------------------------------}
-
-
- function InitHelp (HmiLID: integer): Integer;
-
- var
- Error: OSErr; {*Used to report any operating system errors.*}
- response: Longint; {*Used for responses from the Gestalt function*}
- Err: Integer; {*Used to report any errors from within my Build Menu function*}
- menuNum: integer; {*Basically a dummy variable on this level*}
-
- begin
- InitHelp := noErr; {*Start with no error.*}
- HelpMenuHandle := nil; {*Make sure the handle is nil initially for error trapping*}
- if not USEHMENUS then
- if TrapAvailable(_Gestalt) then {*Check to see if the Gestalt function is available.*}
- begin
- if Gestalt(gestaltHelpMgrAttr, response) = noErr then {*Check for an error in calling the Gestalt function.*}
- if (BTST(response, gestaltHelpMgrPresent)) then {*Test the response to see if the Help Manager is present.*}
- if HMGetHelpMenuHandle(HelpMenuHandle) = noErr then {*Check for an error in getting the handle.*}
- HelpMenuID := kHMHelpMenuID; {*If the Help manager is present and we had no*}
- {*problem getting a handle to the Help menu then we are using System 7 stuff*}
-
- end; {*Otherwise we need to try to build a new menu and add it to the menu bar*}
- if HelpMenuHandle = nil then {*We didn't get a handle to the Help menu, so try to create a new menu*}
- begin
- HelpMenuHandle := NewMenu(NonSevenMenuID, HELPMENUTITLE); {*Get the new menu*}
- if HelpMenuHandle = nil then
- begin
- InitHelp := HelpHandleErr; {*If there was a problem getting a handle to the menu*}
- exit(InitHelp); {*Exit this routine with proper error code.*}
- end;
- insertMenu(HelpMenuHandle, 0); {*Put the new menu in the menubar*}
- HelpMenuID := NonSevenMenuID; {*Set the menu ID for non-System 7 Help menu*}
- end;
- HelpMenuItems := CountMItems(HelpMenuHandle); {*Get the number of menu items initally*}
-
- menuNum := 0; {*The number of the menu we are currently working with.*}
- TheMenu[menuNum].Master := BuildMenu(HmiLID, HelpMenuHandle, menuNum, Err);
- {*Build the first Menu, recursively build the rest and store the master handle.*}
-
- if Err <> noErr then {*Check for an error during the build sequence.*}
- InitHelp := Err; {*Return proper error code.*}
-
- DrawMenuBar; {*Update the menu bar to include all of the new items added.*}
- end;
- {-----------------------------------------------------------------------}
-
- procedure MoveText;
-
- var
- OldOffset, NewOffset: integer; {*The old and new offset of the text in pixels*}
-
- begin
- with TEXTHandle^^ do
- begin
- OldOffset := viewRect.top - destRect.top; {*Calculate the old offset*}
- NewOffset := GetCtlValue(TheScrollBar) * lineheight; {*Calculate the offset to the new posn.*}
- TEScroll(0, (OldOffset - NewOffset), TEXTHandle); {*Scroll to the new position*}
- end;
- end;
- {-----------------------------------------------------------------------}
-
- procedure ScrollPageUp;
-
- var
- OldControl: integer;
- change: integer;
-
- begin
- OldControl := GetCtlValue(TheScrollBar); {*Get the old value*}
- with TEXTHandle^^.viewrect do
- change := (top - bottom) div TEXTHandle^^.lineheight;
- SetCtlValue(TheScrollBar, OldControl + change); {*Set the new value*}
- MoveText;
- end;
- {-----------------------------------------------------------------------}
-
- procedure ScrollPageDown;
-
- var
- OldControl: integer;
- change: integer;
-
- begin
- OldControl := GetCtlValue(TheScrollBar); {*Get the old value*}
- with TEXTHandle^^.viewrect do
- change := (bottom - top) div TEXTHandle^^.lineheight;
- SetCtlValue(TheScrollBar, OldControl + change); {*Set the new value*}
- MoveText;
- end;
- {-----------------------------------------------------------------------}
-
- procedure ScrollUp;
-
- var
- OldControl: integer;
-
- begin
- OldControl := GetCtlValue(TheScrollBar); {*Get the old value*}
- SetCtlValue(TheScrollBar, OldControl - 1); {*Set the new value*}
- MoveText;
- end;
- {-----------------------------------------------------------------------}
-
- procedure ScrollDown;
-
- var
- OldControl: integer;
-
- begin
- OldControl := GetCtlValue(TheScrollBar); {*Get the old value*}
- SetCtlValue(TheScrollBar, OldControl + 1); {*Set the new value*}
- MoveText;
- end;
- {-----------------------------------------------------------------------}
-
- procedure ScrollTop;
-
- var
- TopValue: integer;
-
- begin
- TopValue := GetCtlMin(TheScrollBar); {*Get the minimum value*}
- SetCtlValue(TheScrollBar, TopValue); {*Set the control to top*}
- MoveText;
- end;
- {-----------------------------------------------------------------------}
-
- procedure ScrollBottom;
- var
- BottomValue: integer;
-
- begin
- BottomValue := GetCtlMax(TheScrollBar); {*Get the maximum value*}
- SetCtlValue(TheScrollBar, BottomValue); {*Set the control to bottom*}
- MoveText;
- end;
- {-----------------------------------------------------------------------}
-
- procedure ContinuousScroll (theControl: controlHandle; thePart: integer);
-
- var
- change: integer; {*The amount of scrolling change*}
- OldControl: integer; {*The old value of the control*}
-
- begin
- case thePart of
- inUpButton:
- change := -1; {*If mouse in upButton, scroll text up 1 line*}
- inDownButton:
- change := 1; {*If mouse in downButton, scroll text down 1 line*}
- inPageup:
- with TEXTHandle^^.viewrect do
- change := (top - bottom) div TEXTHandle^^.lineheight;
- {*If mouse in page up, move text up 1 page*}
- inPagedown:
- with TEXTHandle^^.viewrect do
- change := (bottom - top) div TEXTHandle^^.lineheight;
- {*If mouse in page down, move text down 1 page*}
- end;
- if thePart <> 0 then {*Are we still in the same part?*}
- begin
- OldControl := GetCtlValue(theControl); {*Get the old value*}
- SetCtlValue(theControl, OldControl + change); {*Set the new value*}
- MoveText;
- end;
- end;
- {-----------------------------------------------------------------------}
-
- function HelpFilter (theDialog: DialogPtr; var theEvent: EventRecord; var ItemNum: INTEGER): Boolean;
-
- const
- enterKey = 3;
- CR = 13;
- Home = $73;
- Bottom = $77; {*Char and key codes for keyboard events*}
- PageU = $74;
- PageD = $79;
- ArrowUp = 30;
- ArrowDown = 31;
-
- var
- dummyint: integer;
- dummyh: handle; {*Dummy variables for GetDItem calls*}
- TextRect: rect; {*The rect of the Text area*}
- thePoint: Point; {*The point of a mousedown event*}
- thePart: Integer; {*The part of the control where the mouse was pressed*}
- theControl: ControlHandle; {*The control the mouse was pressed in*}
- thePen: PenState; {*Holds the old pen state*}
- tempLong: longint; {*Temporary long integer*}
- theKey: Longint; {*The key code for a key event*}
- TextRgn, TempRgn: RgnHandle; {*Used in determining if the text needs updating*}
- theDialogPeek: DialogPeek; {*Used to get the update region of the dialog*}
-
- begin
- HelpFilter := False;
- case theEvent.what of
- UpdateEvt:
- if theEvent.message = ord4(theDialog) then
- begin
- GetDItem(theDialog, TextBox, dummyint, dummyh, TextRect); {*Get location*}
- insetrect(TextRect, 1, 1);
- GetPenState(thePen); {*Save current pen*}
- Pensize(2, 2);
- insetrect(TextRect, -2, -2); {*Set rectangle to 2 pixels outside of text area*}
- FrameRect(TextRect); {*Draw rect around text*}
- InsetRect(TEXTRect, 2, 2); {*Set rectangle to text area*}
- EraseRect(TextRect); {*Erase the text*}
- TEUpdate(TextRect, TEXTHandle); {*Redraw the text*}
-
- GetDItem(theDialog, 1, dummyint, dummyh, TextRect); {*Get the rect of the ok button*}
- Pensize(3, 3); {*Set the pen to 3 pixels by 3 pixels*}
- InsetRect(TextRect, -4, -4); {*Set the rect around the button*}
- FrameRoundRect(TextRect, 16, 16); {*Draw the outline*}
- SetPenState(thePen); {*Restore the old pen*}
- end;
-
- keydown, autokey:
- begin
- HelpFilter := true; {*Assume we will take care of event*}
- Itemnum := 3; {*Assume a hit on the scroll bar*}
- theKey := BitAnd(theEvent.message, charCodeMask); {*Decode character code*}
- case theKey of
- enterKey, CR:
- begin
- GetDItem(theDialog, 1, dummyint, dummyh, TextRect);
- HiliteControl(ControlHandle(dummyh), 1); {*Fake a click on the OK button*}
- Delay(8, tempLong);
- HiliteControl(ControlHandle(dummyh), 0);
- ItemNum := 1; {*Let ModalDialog know OK button was hit*}
- end;
- ArrowUp:
- Scrollup; {*Scroll text up one line*}
- ArrowDown:
- ScrollDown; {*Scroll text down one line*}
- otherwise
- begin
- theKey := (BitAnd(theEvent.message, KeyCodeMask)) div 256; {*Decode key code*}
- case theKey of
- Home:
- ScrollTop; {*Set text to top*}
- Bottom:
- ScrollBottom; {*Set text to bottom*}
- PageU:
- ScrollPageup; {*Scroll text up one page*}
- PageD:
- ScrollPageDown; {*Scroll text down one page*}
- otherwise
- HelpFilter := false; {*Set return to false if none of these conditions matched*}
- end; {*Case*}
- end; {*Otherwise*}
- end;
- end;
-
- MouseDown:
- begin
- thePoint := theEvent.where; {*Get the point where the mouse was pressed*}
- GlobaltoLocal(thePoint); {*Convert the point to local coordinates*}
-
- thePart := FindControl(thePoint, theDialog, theControl); {*Was mouse in a control?*}
- if thecontrol = TheScrollBar then
- if thePart = InThumb then
- begin
- thePart := TrackControl(TheScrollBar, thePoint, nil);
- MoveText; {*Adjust the text to the movement*}
- HelpFilter := true; {*We handled the event don't let modal dialog take further action*}
- ItemNum := 3 {*Give the return value a number that doesn't correspond to the ok button*}
- end
- else
- begin
- thePart := TrackControl(TheScrollBar, thePoint, @ContinuousScroll);
- HelpFilter := true; {*We handled the event don't let modal dialog take further action*}
- ItemNum := 3 {*Give the return value a number that doesn't correspond to the ok button*}
- end
- end;
- end;
- end;
- {-----------------------------------------------------------------------}
-
- function DoHelp (MenuID, TheItem: integer): Integer;
-
- const
- HelpDialogID = 20000; {*The ID of the Help dialog resource*}
- TheControl = 3; {*The item number of the scroll bar in the help dialog*}
-
- var
- tempHandle: MHandle; {*A temporary handle used in traversing the linked list of menu items.*}
- TextID: integer; {*Will hold the ID of the 'TEXT' resource for the selected item.*}
- TheTitle: Str255; {*The title of the menu item selected*}
- HelpDialogPtr: DialogPtr; {*The pointer to the Help Dialog box*}
- DummyKind: Integer; {*A dummy for use in Get and SetDItem.*}
- TheRect: Rect; {*A rectangle for use in GetDItem.*}
- DummyHandle: Handle; {*A dummy for use in GetDItem.*}
- TheText: Handle; {*A handle to the TEXT resource*}
- DestRect: rect; {*The destination rectangle of the text*}
- MaxLines, LinesVisible: integer; {*Values needed for calculating scrollbar values*}
- TextLength: longint; {*Holds the length of the TEXT resource*}
- SavePort: GrafPtr; {*Holds the old port*}
- TheMenuHandle: MenuHandle; {*Holds the menuHandle of the menu ID passed in*}
-
- begin
- TextID := 0; {*Initially, no TEXT resource selected*}
- DummyKind := 0; {*Start with element 0*}
- while (TheMenu[DummyKind].ID <> MenuID) and (DummyKind <= MaxMenu) do
- DummyKind := DummyKind + 1; {*Find the LL of the requested menu*}
-
- if DummyKind > MaxMenu then {*If DummyKind exceeds the number of allowed menus,*}
- begin {*the menu is not associated with the Help menu*}
- DoHelp := NoMenu; {*so return with proper code*}
- exit(DoHelp)
- end;
-
- TheMenuHandle := GetMHandle(MenuID); {*Get a handle to the selected menu*}
- GetItem(TheMenuHandle, TheItem, TheTitle); {*Get the title of the selected item*}
- tempHandle := TheMenu[DummyKind].Master; {*Set tempHandle equal to the master pointer of the LL.*}
- while TheTitle <> TempHandle^^.ItemTitle do {*Search for the selected item*}
- begin
- tempHandle := TempHandle^^.NextItem;
- if tempHandle = nil then {*This occurs only if we are past the last item in the list.*}
- begin
- DoHelp := DataErr; {*This signifies a data corruption error.*}
- exit(DoHelp)
- end;
- end;
- TextID := TempHandle^^.HelpTextID; {*Set the TEXT ID to the one from the menu item list*}
-
- HelpDialogPtr := GetNewDialog(HelpDialogID, nil, windowPtr(-1)); {*Get the Help Dialog*}
- getport(SavePort); {*Save the old port*}
- SetPort(HelpDialogPtr); {*Set the port to the new dialog*}
- GetDItem(HelpDialogPtr, TheControl, DummyKind, DummyHandle, TheRect);
- TheScrollBar := ControlHandle(DummyHandle); {*Get a control handle to the scroll bar*}
-
- TheText := GetResource('TEXT', TextID); {*Get the TEXT resource*}
- if TheText = nil then
- begin
- DoHelp := DataErr;
- exit(DoHelp) {*This signifies a data corruption error or TEXT resource not available.*}
- end;
-
- GetDItem(HelpDialogPtr, TextBox, DummyKind, DummyHandle, TheRect);
- {*Get the rect of the text box*}
-
- with DestRect do
- begin
- top := TheRect.top + 1;
- left := TheRect.left + 1;
- right := TheRect.right - 1;
- bottom := 20000; {*Set the bottom way down*}
- end;
- InsetRect(TheRect, 1, 1);
- TEXTHandle := TENew(DestRect, TheRect); {*Create a new TE record*}
- Hlock(Handle(TEXTHandle)); {*Lock the text handle down so we can dereference it.*}
-
- {** THESE ARE SET WITH THE GLOBAL VARIABLES **}
- TEXTHandle^^.txFont := FONTFACE; {*Set Font to Selected font face*}
- TEXTHandle^^.txSize := FONTSIZE; {*Set size to selected font size*}
-
- TextLength := SizeResource(TheText); {*Get the length of the text*}
- TEDEactivate(TEXTHandle);
- HLock(TheText); {*Lock down the handle*}
- TEInsert(TheText^, TextLength, TEXTHandle);
- HUnlock(TheText);
-
- with TEXTHandle^^ do
- LinesVisible := (ViewRect.bottom - ViewRect.Top) div lineHeight;
-
- if TEXTHandle^^.nLines > LinesVisible then
- begin
- HiliteControl(TheScrollBar, 0); {*Enable scrollbar if lines are out of view*}
- MaxLines := TEXTHandle^^.nLines - LinesVisible - 1;
- SetCtlMax(TheScrollBar, MaxLines); {*Set the maximum value of the control*}
- end
- else
- begin
- HiliteControl(TheScrollBar, 255); {*Disable the scrollbar if all lines are visible*}
- end;
-
- ShowWindow(HelpDialogPtr); {*Show the window*}
- invalrect(HelpDialogptr^.portrect); {*Force an update on the dialog*}
- repeat
- ModalDialog(@HelpFilter, DummyKind); {*Using dummyKind to save some space*}
- until DummyKind = ok;
-
- HUnlock(Handle(TEXTHandle)); {*Unlock the text handle*}
- DisposDialog(HelpDialogPtr);
- ReleaseResource(TheText); {*Get rid of all this junk before returning*}
- TEDispose(TEXTHandle);
- DoHelp := noErr; {*Return with no error*}
- Setport(SavePort); {*Return port to previous one*}
- end;
- {-----------------------------------------------------------------------}
-
- procedure DisposeHelp;
-
- var
- TempHandle: MHandle;
- DisposableH: MHandle;
- loop: integer;
- MenuItems: integer; {*The number of items in the Help Menu now.*}
-
- begin
- MenuItems := CountMItems(HelpMenuHandle); {*Count the number of items in the Help Menu now*}
-
- for loop := HelpMenuItems + 1 to MenuItems do
- begin
- DelMenuItem(HelpMenuHandle, HelpMenuItems + 1); {*Delete all items in the menu*}
- end;
-
- if HelpMenuHandle^^.menuData = HELPMENUTITLE then
- begin {*If not system 7 help menu we need to kill it.*}
- deleteMenu(HelpMenuID); {*Remove the menu from the menu bar*}
- DrawMenuBar; {*Update menu bar in case application has just turned*}
- {*off this help system*}
- DisposeMenu(HelpMenuHandle); {*Release the menu from memory*}
- end;
-
- for loop := 0 to MaxMenu do {*Dispose of all lists*}
- begin
- DisposableH := TheMenu[loop].Master; {*Get the handle to the first linked list*}
- while DisposableH <> nil do
- begin
- TempHandle := DisposableH^^.NextItem; {*Store the handle to the next item*}
- DisposHandle(Handle(DisposableH)); {*Dispose of the original handle*}
- DisposableH := TempHandle; {*Setup for next disposal*}
- end; {*Keep going until all handles in this list are gone*}
- end;
- end;
- end.